package creators;

import java.util.Scanner;

import simulation.Spring;
import simulation.Model;

/**
 * creator for a Spring object.
 * @author Schwartz & Roy
 *
 */
public class SpringCreator extends Creator {

    /**
     * creates the object.
     * @param model is the model
     * @param line is the input
     */
    @Override
    public void create(Model model, Scanner line) {
        double[] properties = setSpringCommonValues(line);
        model.add(new Spring(model.getMass((int) properties[0]),
                model.getMass((int) properties[1]),
                properties[2], properties[3]));
    }

    /**
     * sets the common values of Spring and Muscle.
     * @param line is the input
     * @return the spring properties as an array with:
     *      index 0 as first massID
     *      index 1 as second massID
     *      index 2 as restlength
     *      index 3 as kval
     */
    protected double[] setSpringCommonValues(Scanner line) {
        int mass1ID = line.nextInt();
        int mass2ID = line.nextInt();
        double restLength = line.nextDouble();
        double ks = line.nextDouble();
        return new double[]{mass1ID, mass2ID, restLength, ks};
    }
}
